import React from 'react'
import { Result, Button } from 'antd'

interface AuthWrapperProps {
  authority: string | string[]
  noMatch?: React.ReactNode
  children: React.ReactNode
}

const AuthWrapper: React.FC<AuthWrapperProps> = ({
  authority,
  noMatch,
  children
}) => {
  // 这里可以从全局状态获取用户权限
  const userAuthorities = ['admin', 'user']

  const hasAuthority = Array.isArray(authority)
    ? authority.some(auth => userAuthorities.includes(auth))
    : userAuthorities.includes(authority)

  if (!hasAuthority) {
    return noMatch || (
      <Result
        status="403"
        title="403"
        subTitle="抱歉，您没有访问此页面的权限"
        extra={
          <Button type="primary" onClick={() => window.history.back()}>
            返回
          </Button>
        }
      />
    )
  }

  return <>{children}</>
}

export default AuthWrapper 